package com.zero2oneblog.entity;

import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonBackReference;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonManagedReference;
import io.swagger.annotations.ApiModel;

import javax.persistence.CascadeType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import java.io.Serializable;
import java.util.List;

/**
 * <p>
 * 
 * </p>
 *
 * @author liangjiu
 * @since 2024-01-09
 */
@TableName("test_post")
@ApiModel(value = "Post对象", description = "")
public class Post implements Serializable {

    private static final long serialVersionUID = 1L;

    private Integer id;

    private String title;

    private String content;

    public Integer getUser_id() {
        return user_id;
    }

    public void setUser_id(Integer user_id) {
        this.user_id = user_id;
    }

    private Integer user_id;

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    @Override
    public String toString() {
        return "Post{" +
            "id = " + id +
            ", title = " + title +
            ", content = " + content +
        "}";
    }

//    @ManyToOne
//    @JoinColumn(name = "user_id")
//    @JsonBackReference
    private User user;

//    @JsonIgnore
    @ManyToOne
    @JoinColumn(name = "user_id")
    @JsonBackReference
    public User getUser() {
        return user;
    }

//    @JsonIgnore
    public void setUser(User user) {
        this.user = user;
    }

    @OneToMany(mappedBy = "post", cascade = CascadeType.ALL)
    @JsonManagedReference
    private List<Comment> comments;

//    @OneToMany(mappedBy = "post", cascade = CascadeType.ALL)
//    @JsonManagedReference
//    @JsonIgnore
    public List<Comment> getComments() {
        return comments;
    }

//    @JsonIgnore
    public void setComments(List<Comment> comments) {
        this.comments = comments;
    }
}
